package edu.mobbuzz.page.menu.category;

import com.sun.lwuit.Button;
import com.sun.lwuit.CheckBox;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;
import edu.mobbuzz.page.menu.Menu;
import edu.mobbuzz.util.string.MenuString;


public class CategoryChoice extends Menu{
    private Form categoryForm;
    private Container categoryPanel;
    private Label menuTitle;
    private int categorySize;
    private CheckBox categoryOptions[];
    private Button addBtn;
    private Command cancelCmd, okCmd;
            
    public CategoryChoice(){
        categoryForm = new Form();
        categoryPanel = new Container();
        menuTitle = new Label(getMenuTitle());
        
        addBtn = new Button();
        
        categoryOptions = new CheckBox[4];        
        categoryOptions[0] = new CheckBox("Politics");
        categoryOptions[1] = new CheckBox("Musics");
        categoryOptions[2] = new CheckBox("Movies");
        categoryOptions[3] = new CheckBox("Education");

        cancelCmd = new Command("Cancel") {
            public void actionPerformed(ActionEvent evt) {
                backToRSSSubscriptionForm();
            }
        };
        
        okCmd = new Command("Done") {
            public void actionPerformed(ActionEvent evt) {
                addToCategory();
            }
        };
        
    }
    
    public void showPage() {
        menuTitle.setAlignment(Component.CENTER);
        menuTitle.getStyle().setMargin(5, 0, 5, 0);
        menuTitle.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        menuTitle.getStyle().setBgTransparency(0);
        
        addBtn.setText("New Category");
        addBtn.getStyle().setMargin(5, 0, 10, 2);
        addBtn.getStyle().setBorder(Border.getEmpty());
        
        categoryOptions[0].getStyle().setMargin(2, 0, 10, 10);
        categoryOptions[1].getStyle().setMargin(2, 0, 10, 10);
        categoryOptions[2].getStyle().setMargin(2, 0, 10, 10);
        categoryOptions[3].getStyle().setMargin(2, 0, 10, 10);
        

        categoryPanel.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        categoryPanel.addComponent(menuTitle);
        categoryPanel.addComponent(addBtn);
        categoryPanel.addComponent(categoryOptions[0]);
        categoryPanel.addComponent(categoryOptions[1]);
        categoryPanel.addComponent(categoryOptions[2]);
        categoryPanel.addComponent(categoryOptions[3]);
        
        categoryForm.setLayout(new BorderLayout());
        categoryForm.addComponent(BorderLayout.CENTER, categoryPanel);
        categoryForm.addCommand(cancelCmd);
        categoryForm.addCommand(okCmd);
        categoryForm.setCommandListener(getActionlistener());
        categoryForm.show();
    }
    
    public void backToRSSSubscriptionForm(){
        
    }
    
    public void addToCategory(){
        
        if(categoryOptions[0].isSelected()) {
            System.out.println("CheckBox 0 got selected");
        } else if(categoryOptions[1].isSelected()) {
           System.out.println("CheckBox 1 got selected");
        } else if(categoryOptions[2].isSelected()) {
           System.out.println("CheckBox 2 got selected");
        } else if(categoryOptions[3].isSelected()) {
           System.out.println("CheckBox 3 got selected");
        }
    }
    public int getCategorySize() {
        return categorySize;
    }

    public void setCategorySize(int categorySize) {
        this.categorySize = categorySize;
    }

    public String getMenuTitle() {
        return MenuString.CATEGORY;
    }

    
    
}
